// 新建comp
const path = require("path")
const fs = require("fs");

// assets 目录
const assetsDir = path.join(path.dirname(__dirname), "assets")
const gameDir = path.join(assetsDir, "script", "game")
// 模块名
const mod = process.argv[2]
// comp name
const compName = process.argv[3]
// 说明
const comment = process.argv[4] || ''
if (!mod || !compName || !comment) {
    console.error("使用方法, tools 目录下运行: node newComp 游戏模块 comp组件名 comp说明")
    process.exit(1)
}

// 首字母大写
const clsName = compName.charAt(0).toUpperCase() + compName.slice(1) + "Comp"

const text = `import {ecs} from "db://oops-framework/libs/ecs/ECS";

// ${comment}
@ecs.register("${clsName}")
export class ${clsName} extends ecs.Comp {
    reset(): void {
    }

}
`

fs.writeFileSync(path.join(gameDir, mod, "comp", compName + "Comp.ts"), text)